
/**
** \file       token.h
**
** \brief      all function and enumeration about the lexing are gathered here
**
** \authors    Bem M'rad Hanna, Boillot Ulysse, De Oliveira Guillaume,
**             Laterem Hamza and Nguyen Viet Dung
**
** \version    0.8
**
** \date       25 November 2013
**
*/

#ifndef TOKEN_H_
# define TOKEN_H_

# define SIZE 23

# include <string.h>
# include <stdlib.h>
# include <stdio.h>
# include <unistd.h>

/**
** \enum       e_token_type
**
** \brief      all token type are referenced here.
**
*/

typedef enum
{
  TOKEN_COMMENT,
  TOKEN_NEWLINE,
  TOKEN_IONUMBER,
  TOKEN_EOF,
  TOKEN_EXCL,
  TOKEN_AND,
  TOKEN_OPEN_P,
  TOKEN_CLOSE_P,
  TOKEN_DAND,
  TOKEN_DOR,
  TOKEN_DSEMI,
  TOKEN_SEMI,
  TOKEN_DGREAT,
  TOKEN_DLESS,
  TOKEN_DLESSDASH,
  TOKEN_LESSAND,
  TOKEN_GREATAND,
  TOKEN_LESSGREAT,
  TOKEN_OR,
  TOKEN_LESS,
  TOKEN_GREAT,
  TOKEN_GREATPIPE,
  TOKEN_WORD
} e_token_type;

/**
** \struct     s_token
**
** \var	type id
**
** \brief      it is the main structure used in the lexer. The lexer
**             returns a token stream associated to the string he got
**             as argument.
**
*/

typedef struct          token
{
    e_token_type        type;
    char                *id;
}                       s_token;

/**
** \var        token_tab_create
**
** \brief      token_tab_create is an array of token. All existing
**             kind of token are in this token.
**
*/

extern s_token  g_token_tab_create[SIZE];

/**
** \struct      s_lexer
**
** \var	token next head
**
** \brief       it is a linked list of s_lexer.
**              It is the struct fill by the lexer.
**
*/

typedef struct          lexer
{
    s_token             *token;
    struct lexer        *next;
    struct lexer        *head;
}                       s_lexer;

/**
** \fn         rec_lexer
**
** \brief      rec_lexer builds the lexer recursively from a string.
**             It works string by string, each call to rec_lexer
**             creates one token.
**
** \param      arguments are the string which as to be transform into a
**             token list and the lexer which is already built.
**
** \return     the lexer built by the function
**
*/

s_lexer         *rec_lexer(char                 *str,
                           s_lexer              *lexer);

/**
** \fn         free_lexer
**
** \brief      free_lexer free allocated memory to the lexer
**
** \param      the lexer which has to be free
**
** \return     void
**
*/

void            free_lexer(s_lexer              *lexer);

#endif /* !TOKEN_H_ */
